Skip to content

Error on invalid store mode #3068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 21, 2025
Merged

Conversation

dstansby
Copy link
Contributor

This avoids instances where mode='r' could be passed, by the resulting array is not read-only. Fixes #2949

@github-actions github-actions bot added needs release notes Automatically applied to PRs which haven't added release notes and removed needs release notes Automatically applied to PRs which haven't added release notes labels May 18, 2025
@dstansby dstansby marked this pull request as ready for review May 18, 2025 16:27
@dstansby dstansby added this to the 3.0.8 milestone May 19, 2025
@d-v-b
Copy link
Contributor

d-v-b commented May 19, 2025

this looks good to me, curious to hear your thoughts @jhamman since you are the mode architect

@dstansby dstansby enabled auto-merge (squash) May 21, 2025 11:31
@dstansby dstansby merged commit 481550a into zarr-developers:main May 21, 2025
29 of 30 checks passed
@maxrjones
Copy link
Member

Would it be possible instead to provide a UserWarning and return a read-only copy of the store? I'm concerned about the downstream impacts of this change (e.g., see xarray failures reported in #3105 (comment)).

@dstansby dstansby deleted the invalid-mode branch May 30, 2025 21:01
@dstansby
Copy link
Contributor Author

My thinking here with an error was to avoid situations where one opened an array with mode='r', but writing to it still worked. So although it has the potential to be disruptive, it's avoiding confusion with the API so I think worth it.

At a slightly higher level, I don't really understand why arrays can't have their own read/write permissions, but I missed that design decision.

@maxrjones
Copy link
Member

My thinking here with an error was to avoid situations where one opened an array with mode='r', but writing to it still worked. So although it has the potential to be disruptive, it's avoiding confusion with the API so I think worth it.

I definitely agree with the premise of avoiding situations where one opened an array with mode='r' but writing still works.

I still question this solution because it will certainly be disruptive. The decision to defer read/write permissions to only the store level is an internal design detail that could be changed without any user facing disruptions, so IMO it'd be better to reconsider that decision before releasing a disruptive change.

IIUC since the array has a reference to the store used at creation rather than a copy, this check doesn't really suffice to solving the situation where one opened an array with mode="r" if the store mode were become mutable (xref #3105). While it seems likely that @d-v-b understands that consequence and is arguing against it, a separate array mode would protect against store changes badly influencing array behavior in a more robust way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Array.read_only incorrect
3 participants